The missing lib
authorStephen Becker IV <github@deathbyescalator.com>
Tue, 17 May 2016 18:54:43 +0000 (11:54 -0700)
committerStephen Becker IV <github@deathbyescalator.com>
Wed, 18 May 2016 19:36:14 +0000 (12:36 -0700)
Dearest Reviewer,

This pull request allows the value of project.links to be passed into
the build script via an environment variable. This closes #1220 . I have
added a test that makes sure that the environment variable is set. Also
note I am using CARGO_LIB not LIB because it appears to be used for
windows in appveyor. I think CARGO_LIB fits better.

I have also updated the documentation to reflect the new variable.

Thanks!
Becker

[Updated]
Github comments moved to CARGO_MANIFEST_LINKS
Fix if statement

src/cargo/ops/cargo_rustc/custom_build.rs
src/doc/environment-variables.md
tests/test_cargo_compile_custom_build.rs

index 9c6b7a2463fa2ad7233b27b303888c0e2c4d5f73..13d3ed0fc1b886b17eb075c42910ba17b36bddaf 100644 (file)
@@ -109,6 +109,10 @@ fn build_work<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
      .env("PROFILE", if cx.build_config.release {"release"} else {"debug"})
      .env("HOST", &cx.config.rustc_info().host);
 
+     if let Some(links) = unit.pkg.manifest().links(){
+        p.env("CARGO_MANIFEST_LINKS", links);
+     }
+
     // Be sure to pass along all enabled features for this package, this is the
     // last piece of statically known information that we have.
     if let Some(features) = cx.resolve.features(unit.pkg.package_id()) {
index 4db72d9d2ed859034c50e5f3da131bd099db7857..201c680ea2747f4bc44c0194b9f6d803f87dbcba 100644 (file)
@@ -68,6 +68,7 @@ let out_dir = env::var("OUT_DIR").unwrap();
                          script). Also note that this is the value of the
                          current working directory of the build script when it
                          starts.
+* `CARGO_MANIFEST_LINKS` - the manifest `links` value.
 * `CARGO_FEATURE_<name>` - For each activated feature of the package being
                            built, this environment variable will be present
                            where `<name>` is the name of the feature uppercased
index dc5d384f9f2558d9256381ea7e7e6996e21ede00..f2690054618309d41a63c34c7933dc69bbc04063 100644 (file)
@@ -353,7 +353,11 @@ test!(links_passes_env_vars {
         "#)
         .file("a/src/lib.rs", "")
         .file("a/build.rs", r#"
+            use std::env;
             fn main() {
+                let lib = env::var("CARGO_MANIFEST_LINKS").unwrap();
+                assert_eq!(lib, "foo");
+
                 println!("cargo:foo=bar");
                 println!("cargo:bar=baz");
             }